from faker import Faker
# 从rich模块导入print，覆盖builtins中的print
from rich import print
from rich.console import Console

console = Console()

fk = Faker('zh_CN')
# 生成测试数据，姓名，语文成绩、数学成绩、英语成绩
scores = [{'name': fk.name(), 'chinese': fk.random_int(0, 100), 'math': fk.random_int(0, 100),
           'english': fk.random_int(0, 100)} for i in range(5)]

scores_sort_by_chinese = sorted(scores, key=lambda score: score['chinese'])
scores_sort_by_math = sorted(scores, key=lambda score: score['math'], reverse=True)
scores_sort_by_english = sorted(scores, key=lambda score: score['english'], reverse=True)
console.rule('排序前')
print(scores)
console.rule('按语文成绩升序排序')
print(scores_sort_by_chinese)
console.rule('按数学成绩降序排序')
print(scores_sort_by_math)
console.rule('按英语成绩降序排序')
print(scores_sort_by_english)

args = "a=3&b=4&c=5"
# 组成字典
listable = {arg.split('=')[0]: arg.split('=')[1] for arg in args.split('&')}
print(listable)

console.rule('不定长的关键字参数')


def double_star_func(**kwargs):
    print("传递的关键字参数有：")
    for key, value in kwargs.items():
        print(f"key: {key}, value: {value}")


double_star_func(a=1, b=2, c='hello python')
double_star_func(host='127.0.0.1', port=3306, user='deploy', database='test')
